home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Online / Apache / include / php / TSRM / TSRM.h < prev   
Encoding:
C/C++ Source or Header  |  2000-12-02  |  3.2 KB  |  117 lines

  1. /*
  2.    +----------------------------------------------------------------------+
  3.    | Thread Safe Resource Manager                                         |
  4.    +----------------------------------------------------------------------+
  5.    | Copyright (c) 1999, 2000, Andi Gutmans, Sascha Schumann, Zeev Suraski|
  6.    | This source file is subject to the TSRM license, that is bundled     |
  7.    | with this package in the file LICENSE                                |
  8.    +----------------------------------------------------------------------+
  9.    | Authors:  Zeev Suraski <zeev@zend.com>                               |
  10.    +----------------------------------------------------------------------+
  11. */
  12.  
  13. #ifndef TSRM_H
  14. #define TSRM_H
  15.  
  16. #ifdef HAVE_CONFIG_H
  17. # include "tsrm_config.h"
  18. #endif
  19.  
  20. /* Only compile multi-threading functions if we're in ZTS mode */
  21. #ifdef ZTS
  22.  
  23. #ifdef WIN32
  24. # define TSRM_WIN32
  25. #endif
  26.  
  27. #ifdef TSRM_WIN32
  28. # include <windows.h>
  29. #elif defined(GNUPTH)
  30. # include <pth.h>
  31. #elif defined(PTHREADS)
  32. # include <pthread.h>
  33. #endif
  34.  
  35. typedef int ts_rsrc_id;
  36.  
  37. #ifdef TSRM_WIN32
  38. #    ifdef TSRM_EXPORTS
  39. #    define TSRM_API __declspec(dllexport)
  40. #    else
  41. #    define TSRM_API __declspec(dllimport)
  42. #    endif
  43. #else
  44. #    define TSRM_API
  45. #endif
  46.  
  47.  
  48. /* Define THREAD_T and MUTEX_T */
  49. #ifdef TSRM_WIN32
  50. # define THREAD_T DWORD
  51. # define MUTEX_T CRITICAL_SECTION *
  52. #elif defined(GNUPTH)
  53. # define THREAD_T pth_t
  54. # define MUTEX_T pth_mutex_t *
  55. #elif defined(PTHREADS)
  56. # define THREAD_T pthread_t
  57. # define MUTEX_T pthread_mutex_t *
  58. #elif defined(NSAPI)
  59. # define THREAD_T SYS_THREAD
  60. # define MUTEX_T CRITICAL
  61. #elif defined(PI3WEB)
  62. # define THREAD_T PIThread *
  63. # define MUTEX_T PISync *
  64. #endif
  65.  
  66. typedef void (*ts_allocate_ctor)(void *);
  67. typedef void (*ts_allocate_dtor)(void *);
  68.  
  69. #define THREAD_HASH_OF(thr,ts)  (unsigned long)thr%(unsigned long)ts
  70.  
  71. #ifdef __cplusplus
  72. extern "C" {
  73. #endif
  74.  
  75. /* startup/shutdown */
  76. TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debug_level, char *debug_filename);
  77. TSRM_API void tsrm_shutdown(void);
  78.  
  79. /* allocates a new thread-safe-resource id */
  80. TSRM_API ts_rsrc_id ts_allocate_id(size_t size, ts_allocate_ctor ctor, ts_allocate_dtor dtor);
  81.  
  82. /* fetches the requested resource for the current thread */
  83. TSRM_API void *ts_resource_ex(ts_rsrc_id id, THREAD_T *th_id);
  84. #define ts_resource(id)            ts_resource_ex(id, NULL)
  85.  
  86. /* frees all resources allocated for the current thread */
  87. TSRM_API void ts_free_thread(void);
  88.  
  89. /* deallocates all occurrences of a given id */
  90. TSRM_API void ts_free_id(ts_rsrc_id id);
  91.  
  92.  
  93. /* Debug support */
  94. #define TSRM_ERROR_LEVEL_ERROR    1
  95. #define TSRM_ERROR_LEVEL_CORE    2
  96. #define TSRM_ERROR_LEVEL_INFO    3
  97. TSRM_API int tsrm_error(int level, const char *format, ...);
  98. TSRM_API void tsrm_error_set(int level, char *debug_filename);
  99.  
  100. /* utility functions */
  101. TSRM_API THREAD_T tsrm_thread_id(void);
  102. TSRM_API MUTEX_T tsrm_mutex_alloc(void);
  103. TSRM_API void tsrm_mutex_free(MUTEX_T mutexp);
  104. TSRM_API int tsrm_mutex_lock(MUTEX_T mutexp);
  105. TSRM_API int tsrm_mutex_unlock(MUTEX_T mutexp);
  106.  
  107. TSRM_API void *tsrm_set_new_thread_begin_handler(void (*new_thread_begin_handler)(THREAD_T thread_id));
  108. TSRM_API void *tsrm_set_new_thread_end_handler(void (*new_thread_end_handler)(THREAD_T thread_id));
  109.  
  110. #ifdef __cplusplus
  111. }
  112. #endif
  113.  
  114. #endif /* ZTS */
  115.  
  116. #endif /* TSRM_H */
  117.